﻿namespace ShootMan
{
    /// <summary>
    /// 自定义excel数据加载类
    /// </summary>
    public class ExcelDataLoader : shaco.ExcelDataLoaderDefault
    {
        shaco.IResources resourecPackage 
        {
            get
            {
                if (null == _resourecPackage)
                {
                    _resourecPackage = new shaco.YooAssetResources();
                    _resourecPackage.SetCurrentPackageName("configs");
                }
                return _resourecPackage;
            }
        }
        shaco.IResources _resourecPackage = null;

        override public shaco.Base.ExcelData Load(string path)
        {
            shaco.Base.ExcelData retValue = null;
            var request = resourecPackage.Load<UnityEngine.Object>(path);
            if (null != request)
            {
                retValue = LoadExcelDataFromResource(request);
            }
            return retValue;
        }

        override public void LoadAsync(string path, System.Action<shaco.Base.ExcelData> callbackEnd, System.Action<float> callbackProgress = null)
        {
            if (null == callbackEnd)
            {
                shaco.Log.Error("ExcelHelper LoadAsync error: callback function is invalid");
                return;
            }

            var request = resourecPackage.LoadAsync<UnityEngine.Object>(path);
            OnLoadAsync(request, callbackEnd, callbackProgress);
        }
    }
}